package com.phoenix;

import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.authority.AuthorityUtils;

/**
 * Created by lilongfei on 16/6/24.
 */
public class LoginAuthenticationProvider implements AuthenticationProvider {

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if (authentication instanceof LoginAuthentication) {
            LoginAuthentication loginAuthentication = (LoginAuthentication) authentication;
            return new LoginAuthentication("john", loginAuthentication.getCredentials()
                    , AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")
                    , "1", "john", "123"
            );
        }
        return null;
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return authentication.isAssignableFrom(LoginAuthentication.class);
    }
}
